package com.pets.springboot_petshop.service.impl;

import com.pets.springboot_petshop.entity.Appointmentslot;
import com.pets.springboot_petshop.entity.DailyProfit;
import com.pets.springboot_petshop.entity.MonthlyProfit;
import com.pets.springboot_petshop.entity.Serviceappointment;
import com.pets.springboot_petshop.mapper.ServiceappointmentMapper;
import com.pets.springboot_petshop.service.ServiceappointmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;

/**
 * @Author: wxk
 * @Email: 2089967794@qq.com
 * @Date: 2024/10/14 下午4:35 周一
 * @Description: 用户服务预约实现类
 */
@Service
public class ServiceappointmentServiceImpl implements ServiceappointmentService {
    // 定时任务，每分钟执行一次
    @Scheduled(fixedRate = 60000)
    public void checkAndUpdateServiceappointment() {
        // 获取当前时间
        LocalDateTime now = LocalDateTime.now();
        // 查询所有已过期的记录
        List<Serviceappointment> expiredAppointments = serviceappointmentMapper.findExpiredServiceappointment(now);
        // 更新这些记录的状态为不可预约
        for (Serviceappointment serviceappointment : expiredAppointments) {
            serviceappointmentMapper.updatestatus(serviceappointment.getId(), "已过期");
        }
    }
    @Autowired
    private ServiceappointmentMapper serviceappointmentMapper;

    @Override
    public Serviceappointment select(int id) {
        return serviceappointmentMapper.select(id);
    }

    @Override
    public List<Serviceappointment> selectappointmentslot_id(int appointmentslot_id) {
        return serviceappointmentMapper.selectappointmentslot_id(appointmentslot_id);
    }

    @Override
    public List<Serviceappointment> selectuser_id(int user_id) {
        return serviceappointmentMapper.selectuser_id(user_id);
    }

    @Override
    public List<Serviceappointment> selectstatus(String status) {
        return serviceappointmentMapper.selectstatus(status);
    }

    @Override
    public List<Serviceappointment> selectname(String name) {
        return serviceappointmentMapper.selectname(name);
    }

    @Override
    public List<Serviceappointment> selectordernumber(int ordernumber) {
        return serviceappointmentMapper.selectordernumber(ordernumber);
    }

    @Override
    public int adminupdate(Serviceappointment serviceappointment) {
        return serviceappointmentMapper.adminupdate(serviceappointment);
    }

    @Override
    public List<Serviceappointment> selectOrder(LocalDate date) {
        return serviceappointmentMapper.selectOrder(date);
    }


    @Override
    public List<Serviceappointment> findAll() {
        return serviceappointmentMapper.findAll();
    }

    @Override
    public int add(Serviceappointment serviceappointment) {
        return serviceappointmentMapper.add(serviceappointment);
    }

    @Override
    public int delete(int id) {
        return serviceappointmentMapper.delete(id);
    }

    @Override
    public int update(Serviceappointment serviceappointment) {
        return serviceappointmentMapper.update(serviceappointment);
    }

    @Override
    public int updateServiceappointmentstatus(Serviceappointment serviceappointment) {
        return serviceappointmentMapper.updateServiceappointmentstatus(serviceappointment);
    }

    @Override
    public int updatetk_status(Serviceappointment serviceappointment) {
        return serviceappointmentMapper.updatetk_status(serviceappointment);
    }

    @Override
    public int batchUpdateStatus(int[] ids, String status) {
        return serviceappointmentMapper.batchUpdateStatus(ids, status);
    }

    @Override
    public int admindelete(int[] ids) {
        return serviceappointmentMapper.admindelete(ids);
    }

    @Override
    public List<MonthlyProfit> selectMonthlyProfit(int year) {
        return serviceappointmentMapper.selectMonthlyProfit(year);
    }

    @Override
    public List<DailyProfit> selectDailyProfit(int year, int month) {
        return serviceappointmentMapper.selectDailyProfit(year, month);
    }
}
